/*
 * @Date: 2020-07-16 17:57:20
 * @LastEditTime: 2021-02-25 15:51:51
 * @Description: 返回的Mock数据
 * @FilePath: \vue-leng\src\mock\mList.js
 * 
 * 
 * 调用./mExtend方式:
 * 例1. mExtend.deviceName()
 * 例2. Mock.mock({"deviceName": "@deviceName"})
 */

import Mock from 'mockjs'
import mExtend from './mExtend'

//处理post返回参数
function geturl(str) {
	var obj = {};
	var arr = str.split('&');
	arr.forEach(e => {
		var arr2 = e.split("=");
		obj[arr2[0]] = arr2[1];
	})
	return obj;
};


// get
const lsTips = ()=>{
	return {
		"success": true,
		"message": "保存巡更线路成功"
	}
}

const lsGetAlarmList = ()=>{
   return Mock.mock({
		"success": true,
		"message": "获取信息成功",
		"count": 8,
		"data|3-20": [{
			"alarmId": "@guid",
			"deviceId": "@deviceId",
			"alarmMessage": "视频监控设备告警推送测试" + "@increment",
			"alarmTime": "@now",
			"link": null,
			"deviceTypeName": "视频监控",
			"deviceName": "@pick(['R19教室广角','R19卫生间门口','R19卫生间窗户','R19卫生间中间','R19宿舍云台','R19宿舍广角','R19活动区西','R19活动区东'])",
			"modelId": "B1_1"
		}],
		"datas|8-30": [{
			"groupId": "@integer(1)",
			"address": "@address",
			"deviceName": "@deviceName",
			"rtsp_url": "@rtspUrl"
		}]
	})
}


// post
const lsPostDeviceInfo = (option)=>{
	const deviceId = geturl(option.body).deviceId;
	// const devs=deviceId.split('-')[0];
	const devs=deviceId.slice(0,2);
	var build;
	switch (devs){
		case "B1":
			build="B1教学用房"
			break;
		case "WJ":
			build="园区"
			break;
		case "XZ":
			build="园区"
			break;
		default:
		console.log('未知场景')
			break;
	};
	return Mock.mock({
		"success": true,
		"message": "获取信息成功",
		"count": "1",
		"data": {
			"deviceId": deviceId,
			"modelId": "B1_1",
			"deviceName": mExtend.deviceName(),
			"deviceTypeName": "视频监控",
			"address": "@address",
			"build": build,
			"floor": "1层",
			"room": "房间@integer(1,20)",
			"xcode": null,
			"ycode": null,
			"zcode": null,
			"xangle": null,
			"yangle": null,
			"zangle": null,
			"alarmArea": "",
			"deviceCode": "",
			"hostIp": "@ip",
			"phoneNumber": "",
			"rtsp_url": "@rtspUrl",
			"remarks": ""
		}
	})
}

//登陆
const lsLogin = (option) => {
	var user = geturl(option.body);
	if (user.userName == "admin" && user.password == "111") {
		return {
			"success": true,
			"message": "登陆成功!"
		}
	} else {
		return {
			"success": false,
			"message": "用户名或密码错误!"
		}
	}
}

export {
	lsTips,
	lsGetAlarmList,
	lsPostDeviceInfo,
	lsLogin
}